import React, { Component } from 'react';
import {Modal,Form,Input,message} from 'antd';
import axios from 'axios';


export default class Adduser extends Component {
  formRef = React.createRef();//重置表单没有实现

  cancelForm=()=>{
    this.formRef.current.resetFields();
    this.props.close()
  }


  handleSubmit=(list)=>{
    let that=this;

    this.formRef.current.validateFields()
    .then(values=>{
      message.info('添加成功！');
      this.cancelForm();

      const token=localStorage.getItem('token');
        if(token){
            // console.log(token);
            axios.post("https://wx.xxmtcds.top:2333/admin/smart",values,{
              headers: { 'authorization': `${token}` }
            })
              .then(function(response){
                console.log(response);
                that.props.get();
              })
              .catch(err=>console.log(err))
      }
      }).catch(errorInfo=>{
        // console.log(errorInfo);
        message.error('添加失败！');
      })

     
  }


  render() {
    // const {userlist}= this.props;
    // console.log(userlist);
    return (
      
      <Modal
          title='添加用户信息'
          okText='确定'
          cancelText='取消'
          visible={this.props.visible}
          onCancel={this.cancelForm}
          onOk={this.handleSubmit}>
      
          <Form 
            ref={this.formRef}
            layout="horizontal"
            labelCol={{span:7}}//不能超过24
            wrapperCol={{span:12}}>
      
            <Form.Item name="smart_tag" label='关键词' 
                rules={[{
                        required:true,
                        message:'请输入关键词',
                    }]}>
              <Input placeholder='关键词' />  
            </Form.Item>

            <Form.Item name="smart_content" label='内容' 
                rules={[{
                        required:true,
                        message:'请输入内容',
                    }]}>
              <Input.TextArea allowClear showCount minRows='5' maxLength={200} />
               
            </Form.Item>


          </Form>
      </Modal>
        

    );
  }
}



